package cn.edu.scau.cmi.wujiaxian.client;


import cn.edu.scau.cmi.wujiaxian.singleton.Marshal;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class MultipleClient extends Application {

	/**
	 * 开始方法
	 */
   @Override
   public void start(Stage primaryStage) {
	   VBox root = new VBox(10);
       multipleton(root);
       
       Scene scene = new Scene(root, 700, 700);
       primaryStage.setTitle("多例模式实验");
       primaryStage.setScene(scene);
       primaryStage.show();
   }

   /**
    * 多例模式的实验
    * @param pane
    */
   public void multipleton(Pane pane) {
	   Text title = new Text("多例模式测试");
	   pane.getChildren().add(title);
	   
	   TextField textField = new TextField();
	   Label label = new Label("元帅名字：");
	   pane.getChildren().addAll(label, textField);
	   
	   Button btn = new Button();
       btn.setText("生成元帅");
       btn.setOnAction(event -> {
    	   Text t = new Text();
    	   t.setText(Marshal.addInstance(textField.getText()));
    	   pane.getChildren().add(t);
       });
       pane.getChildren().add(btn);
   }
   
   public static void main(String[] args) {
//       launch(args);
       Platform.runLater(new Runnable() {
           public void run() {             
               new MultipleClient().start(new Stage());
           }
        });
   }
}